<?php
/**
 * @author 刘国君
 * @version 1.0
 */

namespace app\Handel;


class Sip
{
    static function decode_www_auth($str){
        $ret = [
            'scheme' => '',
        ];
        $kvs = explode(',', $str);
        foreach($kvs as $n=>$kv){
            $kv = trim($kv);
            if($n == 0){
                $ps = explode(' ', $kv, 2);
                $ret['scheme'] = $ps[0];
                $kv = $ps[1];
            }
            list($k, $v) = explode('=', $kv);
            $v = trim($v, '"');
            $ret[$k] = $v;
        }
        return $ret;
    }

    static function encode_www_auth($auth){
        $arr = [];
        foreach($auth as $k=>$v){
            $arr[] = "$k=\"$v\"";
        }
        return "Digest ".join(', ', $arr);
    }
}